<?php
/**
* smarty function to get constant value which define before
* @param  name    the constant name
* @param  assign  the assign to variable name
* @return string of value or assign to value if assign param is set
*/
function smarty_function_hidden_ip($params, &$smarty) 
{
    $ip      = $params['ip'];
    $ipdash = str_replace(".","-",$ip);
    $ipSplit = split("-" ,$ipdash );

    

    if(strlen($ipSplit[3]) == 1){
      $ipHidden = $ipSplit[0].".".$ipSplit[1].".".$ipSplit[2].".x";
    }else if(strlen($ipSplit[3]) == 2){
      $ipHidden = $ipSplit[0].".".$ipSplit[1].".".$ipSplit[2].".xx";
    }else if(strlen($ipSplit[3]) == 3){
      $ipHidden = $ipSplit[0].".".$ipSplit[1].".".$ipSplit[2].".xxx";
    }

    echo $ipHidden;

}